package lession

import (
	"fmt"
)

func SwitchTest() {
	// finger := 4
	// switch finger {
	switch finger := 8; finger {
	case 1:
		fmt.Println("Thumb")
	case 2:
		fmt.Println("Index")
	case 3:
		fmt.Println("Middle")
	case 4:
		fmt.Println("Ring")
	case 5:
		fmt.Println("Pinky")
	default:
		fmt.Println("incorrect finger number")
	}
}

func switchTest2() {
	letter := "i"
	switch letter {
	case "a", "e", "i", "o", "u":
		fmt.Println("vowel")
	default:
		fmt.Println("not a vowel")
	}
}

func getNumber() int {
	num := 15 * 5
	return num
}

/**
 * 1. switch 默认只会匹配第一种 case, 后面的匹配项不会执行
 * 2. fallthrough 则会多次匹配和执行
 */
func SwitchTest3() {
	switch num := getNumber(); {
	case num < 50:
		fmt.Printf("%d is lesser than 50\n", num)
		fallthrough
	case num < 100:
		fmt.Printf("%d is lesser than 100\n", num)
		fallthrough
	case num < 200:
		fmt.Printf("%d is lesser than 200\n", num)
	}
}
